package com.tutor.lzm.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tutor.lzm.R;
import com.tutor.lzm.activity.BaseActivity;

import butterknife.ButterKnife;

public abstract class BaseFragment extends Fragment {
    public final static String fragment_flag = "ZZGDD";
    protected String tag ;
    protected View contentView = null;
    protected BaseActivity mAct;

    @Override
    public void onAttach(Activity activity) {

        super.onAttach(activity);
        this.mAct = (BaseActivity) activity;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {

        if (contentView == null) {
            contentView = inflater.inflate(getFragmentLayout(), container, false);
        }
        ButterKnife.bind(this, contentView);
        initView(bundle);
        initData(bundle);
        return contentView;
    }


    public View findViewById(int id) {
        return contentView.findViewById(id);
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        mAct.notifyBackPressList.add(this);
        tag = getClass().getName();
    }


    protected void initView(Bundle bundle) {

    }

    ;


    protected void initData(Bundle bundle) {

    }

    protected BaseFragment addBundle(BaseFragment fragment, int catlog) {
        Bundle bundle = new Bundle();
        bundle.putInt(fragment_flag, catlog);
        fragment.setArguments(bundle);
        return fragment;
    }

    /**
     * 模拟返回键
     **/
    public void fragmentFinish() {

        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        fragmentManager.popBackStack();

    }

    public boolean onBackPressed() {

        return false;
    }

    /**
     * fragment布局
     *
     * @return int
     * @throws
     * @since 1.0.0
     */
    public abstract int getFragmentLayout();

}
